package com.woniuxy.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author dingpf
 * @version 1.0
 * @description
 * @create 2025/4/21 16:56
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private T data;
    private String msg;

    /**
     * 封装一个成功方法(需要带参数)
     */
    public static <T> ResponseData ok(T data){
        return new ResponseData(ResponseEnum.SUCCESS.getCode(),data,"操作成功");
    }

    public static <T> ResponseData ok(){
        return new ResponseData(ResponseEnum.SUCCESS.getCode(),null,"操作成功");
    }

    /**
     * 封装一个失败方法（业务方面异常返回）
     * 1：系统业务异常返回情况很多 一个异常对应一个code码
     */
    public static <T> ResponseData fail(ResponseEnum responseEnum){
        return new ResponseData(responseEnum.getCode(),null,"操作失败");
    }

}
